package com.ctshk.rpc.order.custom.mapper;


import com.ctshk.rpc.order.custom.base.CustomBaseMapper;
import com.ctshk.rpc.order.custom.dto.order.SumPeopleAmountDTO;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderInsurancePriceTourist;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 保险旅客价格 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-04
 */
public interface CustomizedOrderInsurancePriceTouristMapper extends CustomBaseMapper<CustomizedOrderInsurancePriceTourist> {

    /**
     * 统计保险信息
     * @param orderId
     * @param idList
     * @return
     */
    @Select("SELECT COUNT(*) AS peopleNum,SUM(amount) AS totalAmount\n" +
            "FROM t_customized_order_insurance_price_tourist\n" +
            "WHERE order_id = #{order_id} AND id IN #{list}")
    SumPeopleAmountDTO sumPeopleAmount(@Param("order_id") Long orderId, @Param("list") List<Long> idList);

    /**
     * 旅客是否购买保险
     * @param orderId
     * @param touristId
     * @return
     */
    @Select("SELECT a.* \n" +
            "FROM t_customized_order_insurance_price_tourist a\n" +
            "LEFT JOIN t_customized_order_insurance b ON a.insurance_id = b.id\n" +
            "WHERE a.order_id = #{order_id} AND a.tourist_id = #{tourist_id} AND b.is_pay = 1\n" +
            "LIMIT 1")
    CustomizedOrderInsurancePriceTourist queryByTourist(@Param("order_id")Long orderId, @Param("tourist_id")Long touristId);

    /**
     * 删除旅客参保记录
     * @param schedule
     * @return
     */
    @Update("DELETE FROM t_customized_order_insurance_price_tourist\n" +
            "WHERE schedule_id = #{schedule_id}")
    Integer delBySchedule(@Param("schedule_id") Long schedule);
}
